# -*- coding:utf-8 -*-
#! python3

# FaceCat-Python
#Shanghai JuanJuanMao Information Technology Co., Ltd 

from facecat_objc import *

gPaint = FCPaint() #创建绘图对象

#加载示例
def loadUI():
	xml = """<?xml version="1.0" encoding="utf-8"?>
	<html xmlns="facecat">
	<head>
	</head>
	<body>
		<div dock="fill" type="tab" selectedindex="0">
		<div name="TabPage" text="可视化生成" type="tabpage">
			<div name="Div" text="Div" location="15,31" size="312,279">
			<input type="button" name="Button" text="Button" location="11,22" size="100,20" />
			<input type="checkbox" name="CheckBox" text="CheckBox" location="11,59" size="100,20" />
			<label name="Label" text="Label" location="11,92" size="100,20" />
			<input type="text" name="TextBox" location="11,153" size="100,20" />
			<table name="Grid" text="Grid" location="125,13" size="169,220">
				<tr>
				<th name="FCGridColumn" text="FCGridColumn"></th>
				<th name="FCGridColumn2" text="FCGridColumn2"></th>
				</tr>
				<tr>
				<td>Cell1</td>
				<td>Cell2</td>
				</tr>
			</table>
			</div>
		</div>
		<div name="TabPage2" text="代码创建" type="tabpage" />
		</div>
	</body>
	</html>
	"""
	renderFaceCat(gPaint, xml)
	tabPage = findViewByName("TabPage2", gPaint.views);
	div = FCDiv()
	div.location = FCPoint(50, 50)
	div.size = FCSize(200, 200)
	div.showHScrollBar = True
	div.showVScrollBar = True
	addViewToParent(div, tabPage)
	for i in range(0, 10):
		button = FCButton()
		button.location = FCPoint(i * 40, i * 40)
		button.size = FCSize(100, 20)
		addViewToParent(button, div)
		button.text = "确定"

class AppDelegate(NSObject):
	def windowWillClose_(self, notification):
		os._exit(0)
	def applicationDidFinishLaunching_(self, notification):
		gPaint.size = FCSize(900, 770)
		window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
		NSMakeRect(0, 0, gPaint.size.cx, gPaint.size.cy),
		15,
		NSBackingStoreBuffered,
		False
		)
		window.setDelegate_(self)
		window.orderFrontRegardless()
		view = FCUIView.alloc().initWithFrame_(NSMakeRect(0, 0, gPaint.size.cx, gPaint.size.cy))
		view.paint = gPaint
		window.setContentView_(view)
		gPaint.view = view
		loadUI()

app = NSApplication.sharedApplication()
delegate = AppDelegate.alloc().init()
app.setDelegate_(delegate)
app.run()
